package com.cxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxt.Mapper.TripDataMapper;
import com.cxt.entity.TripData;
import com.cxt.service.ITripDataService;
import com.cxt.vo.TripDataJkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class ITripDataServiceImpl extends ServiceImpl<TripDataMapper, TripData> implements ITripDataService {
    @Autowired
    TripDataMapper tripDataMapper;
    @Override
    public List<TripDataJkVo> getList() {
        //获取
        List<TripDataJkVo> lsit = new ArrayList<>();
        List<Object> objects = tripDataMapper.selectObjs(new LambdaQueryWrapper<TripData>().select(TripData::getTripId));
        List<Long> collect = objects.stream().filter(Objects::nonNull).map(id -> (Long) id).collect(Collectors.toList());
        //去重
        collect = collect.stream().distinct().collect(Collectors.toList());
        for (Long l : collect) {
            TripDataJkVo tripDataJkVo = new TripDataJkVo(l,
                    tripDataMapper.selectList(new LambdaQueryWrapper<TripData>().eq(TripData::getTripId, l)));
            lsit.add(tripDataJkVo);
        }
        return lsit;
    }
}
